<meta charset="UTF-8">
	
	<div  style="height:100%;overflow:auto">
		<form class="form-horizontal" style="padding-top: 18px">
		<div class="form-group" style=" width:500px;height: 40px;margin-bottom: 0px">
					<div class="col-md-5"><span class='h3'>学生管理<small>Student</small></span></div>
					<label class="col-md-3 control-label">选择班级</label>
					<div class="col-md-4">
						<input  class="form-control" type="text" name="Sel" id="Sel" value=""/>
						
					</div>
		</div>
		</form>
		<hr>
		<div id='aa' style="display: none">
		<table id="mytable" ></table>
		</div>
	</div>
	
	<script type="text/javascript">
	$(function(){
	
		$('#Sel').combobox({
			url:'tbclass/list',
			textField: 'name',
			valueField: 'id',
			hidebtn:function(){
				$('#aa').hide();
			},
			onchange:function(newsel){
				var o=document.getElementById('aa'); 		
				o.innerHTML='';
				var table=$('<table id="mytable"/>');
				table.appendTo($('#aa'));
				shuaxin(newsel);
				$('#aa').show();
			}
		})
	})
	
	function shuaxin(bjId){
		$('#mytable').datagrid({
			url:'page?bjId='+bjId,
			editUrl:'edit?bjId='+bjId,
			path:'xuesheng',
			columns:[
				[
					{title:'cb',field:'cb',checkbox:true},
					{title:'学号',field:'stuNo'},
					{title:'姓名',field:'name'},
					{title:'照片',field:'filename',width:250,formatter: function(value,row,index){
		                if (row.filename){
		                	var str = '<button class="btn btn-default btn-xs" onclick="ckimg(\''+row.id+'\')"><span class="glyphicon glyphicon-picture"></span> 显示照片</button>';  
		            		return str;
		                } else {
		                    return '&nbsp&nbsp无照片';
		                }
		            }},
				]		
			],
			buttons:[$.fn.datagrid.toolbar.buttons.add,$.fn.datagrid.toolbar.buttons.edit,$.fn.datagrid.toolbar.buttons.remove,$.fn.datagrid.toolbar.buttons.search,
				$.createBtn({
					iconCls:'glyphicon glyphicon-repeat',
					text:'重置密码',
					handler:function(){
						var row=$('#mytable').bootstrapTable('getSelections');
						if(row.length){
							id=row[0].id;
						}else{
							bootbox.alert('请选择一行再进行此操作');
							return;
						}
						bootbox.confirm({
							message:'是否重置密码！',
							callback:function (value){
								if(value){
									 $.post('xuesheng/reset', {id:id}, function(result){
										 if(result.success){
											 $.messagebox(result.msg,2000);
											}else{
												bootbox.alert(result.msg);
											}
									 })
								}
							},
							buttons:{
								confirm:{
									confirm:'确认',
									className:'btn-primary'
								},
								cancel:{
									confirm:'取消',
									className:'btn-default'
								}
							}
						})
					}
				})
				]
		})
	}
	
	function ckimg(id){
		var dialog=$.createDialog({
			title:'照片',
			buttons:[$.createBtn({
				iconCls:'glyphicon glyphicon-remove',
				text:'关闭',
				btnCls:'btn btn-primary',
				isCloseBtn:true
			})]
		}).on('hidden.bs.modal',function(){ 
			dialog.remove();
		})
		var img=$('<img/>');
		img.attr('src','xuesheng/download?id='+id);
		img.attr('alt','加载失败');
		img.attr('width','100%');
		dialog.find('.modal-body').append(img);
		dialog.modal('show');
	}
	</script>